package com.yanqu.road.server.gameplayer.module.winery;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.badge.BadgeConfig;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.skill.SkillUpgradeInfo;
import com.yanqu.road.entity.config.skin.SkinInfo;
import com.yanqu.road.entity.config.winery.WineryConfig;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.extension.*;
import com.yanqu.road.entity.log.LogWineryDrinker;
import com.yanqu.road.entity.log.LogWineryMake;
import com.yanqu.road.entity.log.LogWineryUpgrade;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.entity.player.UserSkin;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.entity.task.args.WineryMakeArgs;
import com.yanqu.road.entity.winery.*;
import com.yanqu.road.logic.bussiness.player.UserWineryBusiness;
import com.yanqu.road.logic.config.ChannelConfig;
import com.yanqu.road.pb.winery.WineryProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.player.BadgeModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.EarnSpeedModule;
import com.yanqu.road.server.gameplayer.module.player.ExtensionModule;
import com.yanqu.road.server.gameplayer.module.skin.SkinModule;
import com.yanqu.road.server.gameplayer.module.xiaomian.XiaoMianModule;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.curio.CurioMgr;
import com.yanqu.road.server.manger.config.*;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.rank.RankMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class WineryModule extends GeneralModule {
    private static Logger logger = LogManager.getLogger(WineryModule.class.getName());

    private UserWineryInfoData userWineryInfoData = initUserWineryInfoData();

    private Map<Integer, UserWineryData> userWineryDataMap = new ConcurrentHashMap<>();

    private Map<Integer, UserWineryDrinkerData> userWineryDrinkerDataMap = new ConcurrentHashMap<>();


    private final Map<Integer, ExtensionWineryStaff> userWineryStaffMap = new ConcurrentHashMap<>();

    private final Map<Integer, ExtensionWineryStaffColdDown> userWineryStaffColdDownMap = new ConcurrentHashMap<>();

    private final Map<Integer, ExtensionWineryItemInfo> userWineryItemInfoMap = new ConcurrentHashMap<>();

    public WineryModule(GamePlayer player) {
        super(player);
    }

    private final RandomHelper random = new RandomHelper();

    private final Lock activityRankLock = new ReentrantLock();

    private boolean isLoadDB = false;

    @Override
    public boolean loadData() {
        if (this.isLoadDB) {
            return true;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            return true;
        }

        this.userWineryInfoData = UserWineryBusiness.getUserWineryInfoData(this.player.getUserId());
        if (null == this.userWineryInfoData) {
            this.userWineryInfoData = initUserWineryInfoData();
            // 更新勋章
            updateBadge();
        }
        this.userWineryDataMap = UserWineryBusiness.getUserWineryDataMap(this.player.getUserId());

        Map<Integer, WineryConfig> wineryConfigMap = WineryConfigMgr.getWineryConfigMap();
        for (WineryConfig wineryConfig : wineryConfigMap.values()) {
            if (this.userWineryDataMap.containsKey(wineryConfig.getId())) {
                continue;
            }
            UserWineryData userWineryData = initUserWineryData(this.player.getUserId(), wineryConfig.getId());
            this.userWineryDataMap.put(userWineryData.getWineryId(), userWineryData);
        }

        this.userWineryDrinkerDataMap = UserWineryBusiness.getUserWineryDrinkerDataMap(this.player.getUserId());
        this.loadExtensionDB();
        this.isLoadDB = true;
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public void afterLogin() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            return;
        }
        this.syncAllMessage();
        this.clearActivityDataOutTime();
    }

    public void initSystem() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            return;
        }
        this.loadData();
        this.syncAllMessage();
    }

    @Override
    public boolean saveData() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            return false;
        }
        Date date = new Date();
        if (this.userWineryInfoData.isUpdateOption()) {
            if (this.userWineryInfoData.isNeedInsert()) {
                this.userWineryInfoData.setCreateAt(date);
                this.userWineryInfoData.setUpdateAt(date);
                if (UserWineryBusiness.addUserWineryInfoData(this.userWineryInfoData)) {
                    this.userWineryInfoData.setNeedInsert(false);
                }
            } else {
                this.userWineryInfoData.setUpdateAt(date);
                UserWineryBusiness.updateUserWineryInfoData(this.userWineryInfoData);
            }
        }

        for (UserWineryData userWineryData : this.userWineryDataMap.values()) {
            if (userWineryData.isUpdateOption()) {
                if (userWineryData.isNeedInsert()) {
                    userWineryData.setCreateAt(date);
                    userWineryData.setUpdateAt(date);
                    if (UserWineryBusiness.addUserWineryData(userWineryData)) {
                        userWineryData.setNeedInsert(false);
                    }
                } else {
                    userWineryData.setUpdateAt(date);
                    UserWineryBusiness.updateUserWineryData(userWineryData);
                }
            }
        }

        for (UserWineryDrinkerData data : this.userWineryDrinkerDataMap.values()) {
            if (data.isUpdateOption()) {
                if (data.isNeedInsert()) {
                    data.setCreateAt(date);
                    data.setUpdateAt(date);
                    if (UserWineryBusiness.addUserWineryDrinkerData(data)) {
                        data.setNeedInsert(false);
                    }
                } else {
                    data.setUpdateAt(date);
                    UserWineryBusiness.updateUserWineryDrinkerData(data);
                }
            }
        }

        return true;
    }


    private void syncAllMessage() {
        this.syncWineryInfoData();
        this.syncWineryDrinkerArrayData();
        this.syncWineryArrayData(this.userWineryDataMap.values());
        this.syncWineryTypeArrayData();
    }

    private void loadExtensionDB() {
        //获取派遣员工的数据
        UserExtensionData userExtensionWineryStaffData = this.player.getModule(ExtensionModule.class).getUserExtensionData(UserExtensionKeyEnum.WINERY_STAFF);
        List<ExtensionWineryStaff> extensionWineryStaffs = JSON.parseObject(userExtensionWineryStaffData.getStringValue(), new TypeReference<List<ExtensionWineryStaff>>() {
        });

        if (extensionWineryStaffs != null) {
            extensionWineryStaffs.forEach(v -> {
                this.userWineryStaffMap.put(v.getStaffId(), v);
            });
        }

        //获取派遣员工冷却数据
        UserExtensionData userExtensionWineryStaffColdDownData = this.player.getModule(ExtensionModule.class).getUserExtensionData(UserExtensionKeyEnum.WINERY_STAFF_COLD_DOWN);
        List<ExtensionWineryStaffColdDown> extensionWineryStaffColdDowns = JSON.parseObject(userExtensionWineryStaffColdDownData.getStringValue(), new TypeReference<List<ExtensionWineryStaffColdDown>>() {
        });
        if (extensionWineryStaffColdDowns != null) {
            for (ExtensionWineryStaffColdDown wineryStaffColdDown : extensionWineryStaffColdDowns) {
                this.userWineryStaffColdDownMap.put(wineryStaffColdDown.getStaffId(), wineryStaffColdDown);
            }
        }

        //获取酿出的酒道具总数
        UserExtensionData userExtensionWineryItemCountData = this.player.getModule(ExtensionModule.class).getUserExtensionData(UserExtensionKeyEnum.WINERY_ITEM_INFO);
        List<ExtensionWineryItemInfo> extensionWineryItemInfoList = JSON.parseObject(userExtensionWineryItemCountData.getStringValue(), new TypeReference<ArrayList<ExtensionWineryItemInfo>>() {
        });
        if (extensionWineryItemInfoList != null) {
            for (ExtensionWineryItemInfo wineryItemInfo : extensionWineryItemInfoList) {
                this.userWineryItemInfoMap.put(wineryItemInfo.getId(), wineryItemInfo);
            }
        }
    }

    private void updateExtensionWineryStaffDB() {
        String s = JSON.toJSONString(this.userWineryStaffMap.values());
        this.player.getModule(ExtensionModule.class).setUserExtensionData(UserExtensionKeyEnum.WINERY_STAFF, 0, s);
    }

    private void updateExtensionWineryStaffColdDownDB() {
        String s = JSON.toJSONString(this.userWineryStaffColdDownMap.values());
        this.player.getModule(ExtensionModule.class).setUserExtensionData(UserExtensionKeyEnum.WINERY_STAFF_COLD_DOWN, 0, s);
    }

    private void updateExtensionWineryItemInfoDB() {
        String s = JSON.toJSONString(this.userWineryItemInfoMap.values());
        this.player.getModule(ExtensionModule.class).setUserExtensionData(UserExtensionKeyEnum.WINERY_ITEM_INFO, 0, s);
    }

    private UserWineryInfoData initUserWineryInfoData() {
        UserWineryInfoData userWineryInfoData = new UserWineryInfoData();
        userWineryInfoData.setUserId(this.player.getUserId());
        userWineryInfoData.setBadgeLevel(1);
        userWineryInfoData.setPausePatron(new ArrayList<>());
        userWineryInfoData.setNeedInsert(true);
        return userWineryInfoData;
    }


    private UserWineryData initUserWineryData(long userId, int wineryId) {
        UserWineryData userWineryData = new UserWineryData();
        userWineryData.setUserId(userId);
        userWineryData.setWineryId(wineryId);

        userWineryData.setLevel(1);

        userWineryData.setNeedInsert(true);
        return userWineryData;
    }

    private UserWineryData getUserWineryData(int wineryId) {
        return this.userWineryDataMap.get(wineryId);
    }

    public Map<Integer, UserWineryData> getUserWineryDataMap() {
        return this.userWineryDataMap;
    }

    public UserWineryInfoData getUserWineryInfoData() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            return null;
        }
        return this.userWineryInfoData;
    }


    private UserWineryDrinkerData getUserWineryDrinkerData(int drinkerId) {
        UserWineryDrinkerData userWineryDrinkerData = this.userWineryDrinkerDataMap.get(drinkerId);
        if (userWineryDrinkerData == null) {
            userWineryDrinkerData = this.initUserWineryDrinkerData(drinkerId);
        }
        this.userWineryDrinkerDataMap.put(userWineryDrinkerData.getDrinkerId(), userWineryDrinkerData);
        return userWineryDrinkerData;
    }

    private UserWineryDrinkerData initUserWineryDrinkerData(int drinkerId) {
        UserWineryDrinkerData userWineryDrinkerData = new UserWineryDrinkerData();
        userWineryDrinkerData.setUserId(this.player.getUserId());
        userWineryDrinkerData.setDrinkerId(drinkerId);
        userWineryDrinkerData.setRewardList(new ArrayList<>());
        userWineryDrinkerData.setNeedInsert(true);
        return userWineryDrinkerData;
    }

    public WineryProto.WineryUpgradeRespMsg.Builder upgradeWinery(WineryProto.WineryUpgradeReqMsg request) {
        WineryProto.WineryUpgradeRespMsg.Builder resp = WineryProto.WineryUpgradeRespMsg.newBuilder();
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            resp.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return resp;
        }

        UserWineryData userWineryData = this.getUserWineryData(request.getWineryId());
        if (null == userWineryData) {
            resp.setRet(GameErrorCode.E_WINERY_NOT_FOUND);
            return resp;
        }
        WineryConfig wineryConfig = WineryConfigMgr.getWineryConfig(userWineryData.getWineryId());
        if (null == wineryConfig) {
            resp.setRet(GameErrorCode.E_WINERY_NOT_FOUND);
            return resp;
        }
        SkillUpgradeInfo skillUpgradeInfo = SkillMgr.getSkillUpgradeInfo(wineryConfig.getUpgrade(), userWineryData.getLevel());
        if (null == skillUpgradeInfo) {
            resp.setRet(GameErrorCode.E_WINERY_NOT_FOUND);
            return resp;
        }
//        Property property = new Property(1, skillUpgradeInfo.getConsumeCount());
//        if (!this.player.getModule(CurrencyModule.class).removeCurrency(property, eLogMoneyType.Winery, eLogMoneyType.WineryUpgrade)) {
//            resp.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
//            return resp;
//        }

        //这里扣除酒艺值，策划没配表，直接硬编码
        long consumeCount = skillUpgradeInfo.getConsumeCount();
        if (this.userWineryInfoData.getArtValue() < consumeCount) {
            resp.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return resp;
        }
        this.userWineryInfoData.setArtValue(this.userWineryInfoData.getArtValue() - consumeCount);
        this.userWineryInfoData.setUpdateOption();

        int preLevel = userWineryData.getLevel();
        userWineryData.setLevel(userWineryData.getLevel() + 1);
        userWineryData.setUpdateOption();

        double wineryTypeTechnology = this.getWineryTypeTechnology(wineryConfig.getType());
        double[] wineryMakeWeightArray = this.getWineryMakeWeightArray(wineryTypeTechnology);
        for (double v : wineryMakeWeightArray) {
            resp.addWeightArray(v);
        }
        resp.setWineryId(userWineryData.getWineryId());
        resp.setLevel(userWineryData.getLevel());
        resp.setArtValue(this.userWineryInfoData.getArtValue());
        //同步商铺赚速
        player.getModule(EarnSpeedModule.class).scheduleAddSilver();
        this.syncWineryArrayData(this.userWineryDataMap.values());

        AutoLogMgr.add(new LogWineryUpgrade(this.player.getUserId(), 2, request.getWineryId(), preLevel, userWineryData.getLevel(), String.format("%d", consumeCount)));

        return resp;
    }

    /**
     * 同步升级
     */
    public WineryProto.WineryUpgradeOneKeyRespMsg.Builder upgradeWineryOneKey(int region) {

        WineryProto.WineryUpgradeOneKeyRespMsg.Builder clientMsg = WineryProto.WineryUpgradeOneKeyRespMsg.newBuilder();
        clientMsg.setRet(0);

        Map<Integer, Long> costMap = new HashMap<>();
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            clientMsg.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return clientMsg;
        }

        long totalCost = 0L;
        for (Map.Entry<Integer, UserWineryData> dataEntry : userWineryDataMap.entrySet()) {
            Integer wineryId = dataEntry.getKey();
            UserWineryData userWineryData = dataEntry.getValue();
            WineryConfig wineryConfig = WineryConfigMgr.getWineryConfig(userWineryData.getWineryId());
            if(wineryConfig == null){
                continue;
            }
            if(wineryConfig.getType() != region){
                continue;
            }
            SkillUpgradeInfo skillUpgradeInfo = SkillMgr.getSkillUpgradeInfo(wineryConfig.getUpgrade(), userWineryData.getLevel());
            if(skillUpgradeInfo == null){
                continue;
            }
            //这里扣除酒艺值，策划没配表，直接硬编码
            long consumeCount = skillUpgradeInfo.getConsumeCount();
            if (this.userWineryInfoData.getArtValue() < totalCost + consumeCount) {
                clientMsg.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
                return clientMsg;
            }
            totalCost += consumeCount;
            costMap.put(wineryId, consumeCount);
        }

        if(totalCost <= 0){
            return clientMsg;
        }

        this.userWineryInfoData.setArtValue(this.userWineryInfoData.getArtValue() - totalCost);
        this.userWineryInfoData.setUpdateOption();


        for (Map.Entry<Integer, Long> entry : costMap.entrySet()) {
            int wineryId = entry.getKey();
            UserWineryData userWineryData = this.userWineryDataMap.get(wineryId);

            int preLevel = userWineryData.getLevel();
            userWineryData.setLevel(userWineryData.getLevel() + 1);
            userWineryData.setUpdateOption();
            AutoLogMgr.add(new LogWineryUpgrade(this.player.getUserId(), 2, wineryId, preLevel, userWineryData.getLevel(), String.format("%d", entry.getValue())));

            WineryConfig wineryConfig = WineryConfigMgr.getWineryConfig(userWineryData.getWineryId());

            WineryProto.WineryDataTemp.Builder temp = WineryProto.WineryDataTemp.newBuilder();
            temp.setWineryId(userWineryData.getWineryId());
            temp.setLevel(userWineryData.getLevel());

            if (wineryConfig != null) {
                int wineryTypeTechnology = this.getWineryTypeTechnology(wineryConfig.getType(), userWineryData);
                double[] wineryMakeWeightArray = this.getWineryMakeWeightArray(wineryTypeTechnology);
                for (double v : wineryMakeWeightArray) {
                    temp.addNextWeightArray(v);
                }
            }
            clientMsg.addWinery(temp);

        }

        clientMsg.setArtValue(this.userWineryInfoData.getArtValue());

        //同步商铺赚速
        player.getModule(EarnSpeedModule.class).scheduleAddSilver();
        this.syncWineryArrayData(this.userWineryDataMap.values());

        return clientMsg;
    }

    public WineryProto.WineryInfoBadgeUpgradeRespMsg.Builder upgradeWineryBadge() {
        WineryProto.WineryInfoBadgeUpgradeRespMsg.Builder builder = WineryProto.WineryInfoBadgeUpgradeRespMsg.newBuilder();

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            builder.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return builder;
        }


        BadgeConfig wineryBadgeConfig = BadgeConfigMgr.getWineryBadgeConfig(this.userWineryInfoData.getBadgeLevel());
        if (null == wineryBadgeConfig) {
            builder.setRet(GameErrorCode.E_UPGRADE_LEVEL_MAX);
            return builder;
        }
        if (wineryBadgeConfig.getUnlockValue() == 0) {
            builder.setRet(GameErrorCode.E_UPGRADE_LEVEL_MAX);
            return builder;
        }

        if (this.userWineryInfoData.getAromaValue() < wineryBadgeConfig.getUnlockValue()) {
            builder.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return builder;
        }

        int preLevel = this.userWineryInfoData.getBadgeLevel();
        BadgeConfig wineryBadgeConfigNext = BadgeConfigMgr.getWineryBadgeConfig(this.userWineryInfoData.getBadgeLevel() + 1);
        if (null == wineryBadgeConfigNext) {
            builder.setRet(GameErrorCode.E_UPGRADE_LEVEL_MAX);
            return builder;
        }

        this.userWineryInfoData.setBadgeLevel(this.userWineryInfoData.getBadgeLevel() + 1);
        this.userWineryInfoData.setUpdateOption();
        builder.setBadgeLevel(this.userWineryInfoData.getBadgeLevel());
        //同步商铺赚速
        player.getModule(EarnSpeedModule.class).scheduleAddSilver();
        // 更新勋章
        updateBadge();
        this.changeAromaRank(0);
        AutoLogMgr.add(new LogWineryUpgrade(this.player.getUserId(), 1, 0, preLevel, this.userWineryInfoData.getBadgeLevel(), String.format("%d", wineryBadgeConfig.getUnlockValue())));

        return builder;
    }


    public WineryProto.WineryMakeRespMsg.Builder makeWinery(WineryProto.WineryMakeReqMsg request) {
        WineryProto.WineryMakeRespMsg.Builder builder = WineryProto.WineryMakeRespMsg.newBuilder();

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            builder.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return builder;
        }

        if (request.getItemId() == 0 || request.getItemNum() == 0) {
            builder.setRet(GameErrorCode.E_BAG_USE_GOODS_COUNT_LESS_ONE);
            return builder;
        }

        GoodsInfo info = GoodsMgr.getGoodsById(request.getItemId());
        if (info == null) {
            builder.setRet(GameErrorCode.E_BAG_ITEM_NO_EXIST);
            return builder;
        }
        int itemWineryType = info.getParamList().get(0).intValue();


        if (info.getType() != eGoodsType.WineryMaterials.getValue()) {
            builder.setRet(GameErrorCode.E_WINERY_ERROR_MAKE_ITEM);
            return builder;
        }

        Property consume = new Property(request.getItemId(), request.getItemNum());
        if (!this.player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.Winery, eLogMoneyType.WineryMake)) {
            player.notifyListener(eGamePlayerEventType.RechargeWineryMake.getValue(), 0);
            player.notifyListener(eGamePlayerEventType.RechargeWineryMakeNew.getValue(), 0);
            builder.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return builder;
        }
        int addArtValue = 0;
        int addAromaValue = 0;
        for (WineryConfig wineryConfig : WineryConfigMgr.getWineryConfigMap().values()) {
            if (wineryConfig.getType() != itemWineryType) {
                continue;
            }
            UserWineryData userWineryData = this.getUserWineryData(wineryConfig.getId());
            if (userWineryData == null) {
                continue;
            }
            for (Integer skillId : wineryConfig.getSkillList()) {
                SkillInfo skillInfo = SkillMgr.getSkillInfo(skillId);
                if (skillInfo == null) {
                    continue;
                }
                if (itemWineryType != skillInfo.getParamList().get(2)) {
                    continue;
                }
                //122	提升酿造特定酒品时所获得的酒香值	提升效果=a	初始固定值		1粮食酒、2花果酒、3高粱酒
                if (skillInfo.getType() == eSkillType.WineryIncreaseAroma.getValue()) {
                    int skillAdd = skillInfo.getParamList().get(0) + (userWineryData.getLevel() - 1) * skillInfo.getUpgradeParamList().get(0);
                    //藏品加成
                    long curioAddition = CurioMgr.getSkillAdditionBySkillType(eSkillType.WineryAromaSkill.getValue(), player, 0);
                    skillAdd = BigDecimal.valueOf(skillAdd).multiply(BigDecimal.valueOf(1000 + curioAddition)).divide(BigDecimal.valueOf(1000), 0, BigDecimal.ROUND_UP).intValue();

                    addAromaValue += skillAdd;
                } else if (skillInfo.getType() == eSkillType.WineryIncreaseArt.getValue()) { //123	提升酿造特定酒品时所获得的酒艺值	提升效果=a	初始固定值		1粮食酒、2花果酒、3高粱酒
                    addArtValue += skillInfo.getParamList().get(0) + (userWineryData.getLevel() - 1) * skillInfo.getUpgradeParamList().get(0);
                }
            }
        }

        Property reward = new Property();
        Property extendReward = new Property();//额外的奖励
        for (int i = 0; i < request.getItemNum(); i++) {
            int wineryTypeTechnology = this.getWineryTypeTechnology(itemWineryType);
            double[] weightArray = this.getWineryMakeWeightArray(wineryTypeTechnology);
            double totalWeight = 0;
            for (double v : weightArray) {
                totalWeight = totalWeight + v;
            }
            int quality = 1;
            double nextDouble = this.random.nextDouble(0, totalWeight);
            for (int i1 = 0; i1 < weightArray.length; i1++) {
                if (nextDouble > weightArray[i1]) {
                    nextDouble = nextDouble - weightArray[i1];
                } else {
                    quality = i1 + 1;
                    break;
                }
            }

            GoodsInfo goodsInfo = GoodsMgr.getWineryGoodsInfo(itemWineryType, quality);
            if (goodsInfo == null) {
                continue;
            }
            if (goodsInfo.getType() == eGoodsType.Winery.getValue()) {
                this.addWineryItemCount(goodsInfo.getGoodsId(), 1);
            }
            reward.addProperty(goodsInfo.getGoodsId(), BigInteger.valueOf(1));
            //额外的奖励
            Property zjBeerOneReward = this.makeExtendReward();
            extendReward.addProperty(zjBeerOneReward);
        }
        addAromaValue = addAromaValue * request.getItemNum();
        addArtValue = addArtValue * request.getItemNum();
        this.player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Winery, eLogMoneyType.WineryMake);
        //添加额外的奖励
        if (!extendReward.isNothing()) {
            this.player.getModule(CurrencyModule.class).addCurrency(extendReward, eLogMoneyType.Winery, eLogMoneyType.WineryMake);
            builder.setExtendReward(PropertyHelper.parsePropertyToString(extendReward));
        }

        this.updateExtensionWineryItemInfoDB();

        this.userWineryInfoData.addArtValue(addArtValue);
        this.userWineryInfoData.addAromaValue(addAromaValue);

        player.notifyListener(eGamePlayerEventType.WineryAromaScoreRise.getValue(),addAromaValue);

        this.userWineryInfoData.setUpdateOption();

        builder.setAddArtValue(addArtValue);
        builder.setAddAromaValue(addAromaValue);
        builder.setWineryType(itemWineryType);
        reward.getGoods().forEach((k, v) -> {
            WineryProto.Item.Builder itemBuilder = WineryProto.Item.newBuilder();
            itemBuilder.setId(k);
            itemBuilder.setNum(v.intValue());
            WineryMakeArgs wineryMakeArgs = new WineryMakeArgs(k, v);
            player.notifyListener(eGamePlayerEventType.WineryMakeTimes.getValue(), wineryMakeArgs);

            //加一下平台接口数据
            player.getModule(XiaoMianModule.class).addWineryMakeTimes(v.longValue());

            builder.addRewardList(itemBuilder);
        });

        this.changeAromaRank(addAromaValue);
        String cost = String.format("%d|%d", request.getItemId(), request.getItemNum());
        String reward1 = String.format("%d|%d", addAromaValue, addArtValue);
        String reward2 = PropertyHelper.parsePropertyToString(reward);
        AutoLogMgr.add(new LogWineryMake(this.player.getUserId(), cost, request.getItemNum(), reward1, reward2));

        Property newConsume = new Property(request.getItemId(), 1);
        if(!player.getModule(CurrencyModule.class).currencyIsEnough(newConsume)){
            player.notifyListener(eGamePlayerEventType.RechargeWineryMakeNew.getValue(), 0);
        }
        return builder;
    }

    /**
     * 酿酒额外的奖励
     * @return
     */
    private Property makeExtendReward() {
        Property property = new Property();
        //珠江啤酒
        Property zjBeerOneReward = this.makeZjBeer();
        property.addProperty(zjBeerOneReward);
        return property;
    }

    /**
     * 产出珠江啤酒
     * @return
     */
    private Property makeZjBeer() {
        boolean useReview = false;
        int channelId = ServerListMgr.getChannelId(GameServer.getInstance().getServerId());
        if(eChannelType.isMainLandChannel(channelId)){
            ServerInfo serverInfo = ServerListMgr.getServerInfo(GameServer.getInstance().getServerId());
            if(null != serverInfo && serverInfo.getServerType() == ServerListMgr.SERVER_TYPE_REVIEW){//提审服用提审配置
                useReview = true;
            }
        }
        if(useReview){
            if (ChannelConfig.ZJ_DEER_LINKAGE_SWITCH_REVIEW == 1 || ChannelConfig.ZJ_DEER_LINKAGE_SWITCH_REVIEW == 2 || ChannelConfig.ZJ_DEER_LINKAGE_SWITCH_REVIEW == 3) {
                //获取珠江啤酒道具信息
                GoodsInfo goodsInfo = GoodsMgr.getGoodsById(eItemId.ZJ_BEER_PROP_ITEM_ID.getValue());
                if (goodsInfo != null) {
                    BigInteger rateBig = goodsInfo.getParamList().get(0);
                    boolean flag = RandomHelper.randRate(rateBig.intValue());
                    if (flag) {
                        //命中，产出珠江啤酒
                        String reward = goodsInfo.getExtendParam();
                        return PropertyHelper.parseStringToProperty(reward);
                    }
                }
            }
        }else {
            if (ChannelConfig.ZJ_DEER_LINKAGE_SWITCH == 1 || ChannelConfig.ZJ_DEER_LINKAGE_SWITCH == 2 || ChannelConfig.ZJ_DEER_LINKAGE_SWITCH == 3) {
                //获取珠江啤酒道具信息
                GoodsInfo goodsInfo = GoodsMgr.getGoodsById(eItemId.ZJ_BEER_PROP_ITEM_ID.getValue());
                if (goodsInfo != null) {
                    BigInteger rateBig = goodsInfo.getParamList().get(0);
                    boolean flag = RandomHelper.randRate(rateBig.intValue());
                    if (flag) {
                        //命中，产出珠江啤酒
                        String reward = goodsInfo.getExtendParam();
                        return PropertyHelper.parseStringToProperty(reward);
                    }
                }
            }
        }
        return null;
    }

    public WineryProto.WineryDrinkerDrinkRespMsg.Builder wineryDrinkerDrink(WineryProto.WineryDrinkerDrinkReqMsg request) {
        WineryProto.WineryDrinkerDrinkRespMsg.Builder builder = WineryProto.WineryDrinkerDrinkRespMsg.newBuilder();

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            builder.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return builder;
        }

        GoodsInfo info = GoodsMgr.getGoodsById(request.getItemId());
        if (info == null) {
            builder.setRet(GameErrorCode.E_BAG_ITEM_NO_EXIST);
            return builder;
        }

        if (info.getType() != eGoodsType.Winery.getValue()) {
            builder.setRet(GameErrorCode.E_WINERY_DRINK_ITEM_ERROR);
            return builder;
        }

        Property consume = new Property(request.getItemId(), 1);
        if (!this.player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.Winery, eLogMoneyType.WineryDrinkerDrink)) {
            builder.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return builder;
        }

        int preFeelingOfDrunk = this.userWineryInfoData.getCurrentDrinkerFeelingOfDrunk();
        int preFriendValue = this.userWineryInfoData.getCurrentDrinkerFriendlyValue();
        this.userWineryInfoData.addCurrentDrinkerIncome(info.getParamList().get(1).intValue());
        this.userWineryInfoData.addCurrentDrinkerFriendlyValue(info.getParamList().get(2).intValue());
        this.userWineryInfoData.addCurrentDrinkerFeelingOfDrunk(info.getParamList().get(3).intValue());
        this.userWineryInfoData.addCurrentDrinkerDrunkNum(1);
        this.userWineryInfoData.setUpdateOption();
        builder.setDrinkerId(this.userWineryInfoData.getCurrentDrinkerId());
        builder.setDrinkerFeelingOfDrunk(this.userWineryInfoData.getCurrentDrinkerFeelingOfDrunk());
        builder.setDrinkerFriendlyValue(this.userWineryInfoData.getCurrentDrinkerFriendlyValue());
        builder.setDrinkerIncome(this.userWineryInfoData.getCurrentDrinkerIncome());
        builder.setDrinkerDrinkNum(this.userWineryInfoData.getCurrentDrinkerDrunkNum());
        int drinkerIncomeFinalValue = this.getDrinkerIncomeFinalValue(this.userWineryInfoData.getCurrentDrinkerFriendlyValue(), this.userWineryInfoData.getCurrentDrinkerIncome());
        builder.setDrinkerFinalIncome(drinkerIncomeFinalValue);

        int currentDrinkerId = this.userWineryInfoData.getCurrentDrinkerId();
        int currentDrinkerFeelingOfDrunk = this.userWineryInfoData.getCurrentDrinkerFeelingOfDrunk();
        int currentDrinkerFriendlyValue = this.userWineryInfoData.getCurrentDrinkerFriendlyValue();
        AutoLogMgr.add(new LogWineryDrinker(this.getUserId(), currentDrinkerId, String.format("%d", request.getItemId()), preFeelingOfDrunk, currentDrinkerFeelingOfDrunk, preFriendValue, currentDrinkerFriendlyValue, drinkerIncomeFinalValue));

        if (this.isCurrentDrinkerDrunk()) {
            this.syncWineryInfoData();
        }
        return builder;
    }

    public WineryProto.WineryDrinkerRewardRespMsg.Builder drinkerReward(WineryProto.WineryDrinkerRewardReqMsg reqMsg) {
        WineryProto.WineryDrinkerRewardRespMsg.Builder builder = WineryProto.WineryDrinkerRewardRespMsg.newBuilder();

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            builder.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return builder;
        }

        UserWineryDrinkerData userWineryDrinkerData = this.getUserWineryDrinkerData(reqMsg.getDrinkerId());
        for (Integer rewardId : reqMsg.getRewardIdListList()) {
            if (rewardId > userWineryDrinkerData.getFriendlyValue()) {
                builder.setRet(GameErrorCode.E_WINERY_DRINKER_FRIENDLY_VALUE_NOT_ENOUGH);
                return builder;
            }
            long count = userWineryDrinkerData.getRewardList().stream().filter(v -> v.equals(rewardId)).limit(1).count();
            if (count > 0) {
                builder.setRet(GameErrorCode.E_WINERY_DRINKER_ALREADY_REWARD);
                return builder;
            }
            Map<Integer, Property> wineryFriendlyRewardMap = ConfigMgr.getWineryFriendlyRewardMap();
            Property property = wineryFriendlyRewardMap.get(rewardId);
            if (property == null) {
                builder.setRet(GameErrorCode.E_WINERY_REWARD_NOT_EXIST);
                return builder;
            }
        }

        reqMsg.getRewardIdListList().forEach(rewardId -> {
            Map<Integer, Property> wineryFriendlyRewardMap = ConfigMgr.getWineryFriendlyRewardMap();
            Property property = wineryFriendlyRewardMap.get(rewardId);
            this.player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.Winery, eLogMoneyType.WineryDrinkerReward);
            userWineryDrinkerData.getRewardList().add(rewardId);
        });

        builder.setDrinkerId(reqMsg.getDrinkerId());
        userWineryDrinkerData.setUpdateOption();
        builder.addAllRewardList(userWineryDrinkerData.getRewardList());
        return builder;
    }

    public WineryProto.WineryDispatchStaffRespMsg.Builder dispatchStaff(WineryProto.WineryDispatchStaffReqMsg reqMsg) {
        WineryProto.WineryDispatchStaffRespMsg.Builder builder = WineryProto.WineryDispatchStaffRespMsg.newBuilder();


        builder.setRet(GameErrorCode.E_WINERY_STAFF_NOT_OPEN);
        return builder;

//        BadgeConfig badgeConfig = BadgeConfigMgr.getWineryBadgeConfig(this.userWineryInfoData.getBadgeLevel());
//        if (badgeConfig == null) {
//            builder.setRet(GameErrorCode.E_WINERY_BADGE_LEVEL_NOT_EXIST);
//            return builder;
//        }
//        if (reqMsg.getPosition() > Integer.parseInt(badgeConfig.getSpecialEffect())) {
//            builder.setRet(GameErrorCode.E_WINERY_TYPE_POSITION_LOCK);
//            return builder;
//        }
//        boolean containsKey = this.userWineryStaffMap.containsKey(reqMsg.getStaffId());
//        if (containsKey) {
//            builder.setRet(GameErrorCode.E_WINERY_STAFF_ALREADY_DISPATCH);
//            return builder;
//        }
//        ExtensionWineryStaffColdDown extensionWineryStaffColdDown = this.userWineryStaffColdDownMap.get(reqMsg.getStaffId());
//        if (extensionWineryStaffColdDown != null) {
//            long currentTimeMillis = System.currentTimeMillis();
//            int coolDownTimeHour = ConfigMgr.getWineryDispatchCoolDownTimeHour();
//            if (currentTimeMillis - extensionWineryStaffColdDown.getFireTimeUnix() < (long) coolDownTimeHour * 60 * 60) {
//                builder.setRet(GameErrorCode.E_WINERY_TYPE_STAFF_UN_COLD_DOWN);
//                return builder;
//            }
//        }
//        long count = this.userWineryStaffMap.values().stream().
//                filter(v -> v.getWineryType() == reqMsg.getWineryType()).
//                filter(v -> v.getPosition() == reqMsg.getPosition()).
//                limit(1).
//                count();
//        if (count > 0) {
//            builder.setRet(GameErrorCode.E_WINERY_TYPE_POSITION_ALREADY_HAS_STAFF);
//            return builder;
//        }
//
//        ExtensionWineryStaff wineryStaff = new ExtensionWineryStaff();
//        wineryStaff.setWineryType(reqMsg.getWineryType());
//        wineryStaff.setPosition(reqMsg.getPosition());
//        wineryStaff.setStaffId(reqMsg.getStaffId());
//        this.userWineryStaffMap.put(wineryStaff.getStaffId(), wineryStaff);
//        this.updateExtensionWineryStaffDB();
//
//        WineryProto.WineryTypeStaffTemp.Builder wineryTypeStaffBuilder = WineryProto.WineryTypeStaffTemp.newBuilder();
//        wineryTypeStaffBuilder.setStaffId(wineryStaff.getStaffId());
//        wineryTypeStaffBuilder.setWineryType(wineryStaff.getWineryType());
//        wineryTypeStaffBuilder.setPosition(wineryStaff.getPosition());
//        //todo
//        wineryTypeStaffBuilder.setAbility(1);
//        builder.setData(wineryTypeStaffBuilder);
//
//        List<WineryProto.StaffSkillTemp.Builder> staffSkill = this.getStaffSkill();
//        staffSkill.forEach(builder::addSkillList);
//
//        return builder;
    }

    public WineryProto.WineryFireStaffRespMsg.Builder fireStaff(WineryProto.WineryFireStaffReqMsg reqMsg) {
        WineryProto.WineryFireStaffRespMsg.Builder builder = WineryProto.WineryFireStaffRespMsg.newBuilder();


        builder.setRet(GameErrorCode.E_WINERY_STAFF_NOT_OPEN);
        return builder;


//        boolean containsKey = this.userWineryStaffMap.containsKey(reqMsg.getStaffId());
//        if (!containsKey) {
//            builder.setRet(GameErrorCode.E_WINERY_TYPE_STAFF_UN_DISPATCH);
//            return builder;
//        }
//
//        this.userWineryStaffMap.remove(reqMsg.getStaffId());
//        this.updateExtensionWineryStaffDB();
//
//        ExtensionWineryStaffColdDown wineryStaffColdDown = new ExtensionWineryStaffColdDown(reqMsg.getStaffId());
//        long currentTimeMillis = System.currentTimeMillis();
//        wineryStaffColdDown.setFireTimeUnix(currentTimeMillis);
//
//        this.userWineryStaffColdDownMap.put(wineryStaffColdDown.getStaffId(), wineryStaffColdDown);
//        this.updateExtensionWineryStaffColdDownDB();
//
//        WineryProto.WineryStaffColdDownTemp.Builder staffColdDown = WineryProto.WineryStaffColdDownTemp.newBuilder();
//        staffColdDown.setStaffId(wineryStaffColdDown.getStaffId());
//        staffColdDown.setFireTimeUnix(wineryStaffColdDown.getFireTimeUnix());
//        builder.setData(staffColdDown);
//        this.getStaffSkill().forEach(builder::addSkillList);
//        return builder;
    }

    private boolean isCurrentDrinkerDrunk() {
        return this.userWineryInfoData.getCurrentDrinkerFeelingOfDrunk() >= 100;
    }

    private void syncWineryInfoData() {
        //这里领取初始奖励
        if (this.userWineryInfoData.getInitReward() == 0) {
            this.player.getModule(CurrencyModule.class).addCurrency(ConfigMgr.getWineryInitItemReward(), eLogMoneyType.Winery, eLogMoneyType.WineryInitItemReward);
            this.userWineryInfoData.setInitReward(1);
            this.userWineryInfoData.setUpdateOption();
        }

        WineryProto.WineryInfoDataSync.Builder builder = WineryProto.WineryInfoDataSync.newBuilder();

        //如果没有当前的酒客，或者当前的酒客已经醉了，需要刷新洒客，或结算酒客信息
        if (this.userWineryInfoData.getCurrentDrinkerId() == 0 || this.isCurrentDrinkerDrunk()) {
            if (this.isCurrentDrinkerDrunk()) {
                UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(this.userWineryInfoData.getCurrentDrinkerId());
                int currentDrinkerIncome = this.userWineryInfoData.getCurrentDrinkerIncome();
                int drinkerIncomeFinalValue = this.getDrinkerIncomeFinalValue(this.userWineryInfoData.getCurrentDrinkerFriendlyValue(), currentDrinkerIncome);
                userPatrons.setBaiYeExp(userPatrons.getBaiYeExp() + drinkerIncomeFinalValue);
                userPatrons.setUpdateOption();
                this.player.getModule(PatronsModule.class).syncPatronsData(userPatrons);

                UserWineryDrinkerData userWineryDrinkerData = this.getUserWineryDrinkerData(this.userWineryInfoData.getCurrentDrinkerId());
                userWineryDrinkerData.setFriendlyValue(userWineryDrinkerData.getFriendlyValue() + this.userWineryInfoData.getCurrentDrinkerFriendlyValue());
                userWineryDrinkerData.setUpdateOption();
                this.syncWineryDrinkerArrayData(userWineryDrinkerData);
            }

            List<UserPatrons> userPatronsList = this.player.getModule(PatronsModule.class).getUserPatronsList();
            ArrayList<Integer> randList = new ArrayList<>();
            for (UserPatrons userPatron : userPatronsList) {
                if (userPatron.getPatronsId() == this.userWineryInfoData.getCurrentDrinkerId()) {
                    continue;
                }
                randList.add(userPatron.getPatronsId());
            }
            Random random = new Random();
            int i = random.nextInt(randList.size());
            this.userWineryInfoData.setCurrentDrinkerId(randList.get(i));
            this.userWineryInfoData.setCurrentDrinkerFeelingOfDrunk(0);
            this.userWineryInfoData.setCurrentDrinkerFriendlyValue(0);
            this.userWineryInfoData.setCurrentDrinkerIncome(0);
            this.userWineryInfoData.setCurrentDrinkerDrunkNum(0);
            this.userWineryInfoData.setUpdateOption();

        }

        builder.setCurrentDrinkerId(this.userWineryInfoData.getCurrentDrinkerId());
        builder.setCurrentDrinkerFeelingOfDrunk(this.userWineryInfoData.getCurrentDrinkerFeelingOfDrunk());
        builder.setCurrentDrinkerFriendlyValue(this.userWineryInfoData.getCurrentDrinkerFriendlyValue());
        builder.setCurrentDrinkerIncome(this.userWineryInfoData.getCurrentDrinkerIncome());
        builder.setCurrentDrinkerDrinkNum(this.userWineryInfoData.getCurrentDrinkerDrunkNum());
        builder.setAromaValue(this.userWineryInfoData.getAromaValue());
        builder.setArtValue(this.userWineryInfoData.getArtValue());
        builder.setBadgeLevel(this.userWineryInfoData.getBadgeLevel());
        builder.addAllPatronId(this.userWineryInfoData.getPausePatron());


        this.userWineryItemInfoMap.forEach((k, v) -> {
            WineryProto.WineryItemTemp.Builder wineryItemBuilder = WineryProto.WineryItemTemp.newBuilder();
            wineryItemBuilder.setItemId(v.getId());
            wineryItemBuilder.setItemNum(v.getNum());
            wineryItemBuilder.setLevel(v.getLevel());
            builder.addWineryItemList(wineryItemBuilder);
        });

        this.player.sendPacket(ClientProtocol.U_WINERY_INFO_DATA_SYNC, builder);
    }

    private void syncWineryDrinkerArrayData() {
        this.syncWineryDrinkerArrayData(this.userWineryDrinkerDataMap.values());
    }

    private void syncWineryDrinkerArrayData(UserWineryDrinkerData userWineryDrinkerData) {
        if (userWineryDrinkerData == null) {
            return;
        }
        List<UserWineryDrinkerData> list = new ArrayList<>();
        list.add(userWineryDrinkerData);
        this.syncWineryDrinkerArrayData(list);
    }

    private void syncWineryDrinkerArrayData(Collection<UserWineryDrinkerData> list) {
        WineryProto.WineryDrinkerDataArraySync.Builder builder = WineryProto.WineryDrinkerDataArraySync.newBuilder();
        for (UserWineryDrinkerData userWineryDrinkerData : list) {
            WineryProto.WineryDrinkerTemp.Builder temp = WineryProto.WineryDrinkerTemp.newBuilder();
            temp.setId(userWineryDrinkerData.getDrinkerId());
            temp.setFriendlyValue(userWineryDrinkerData.getFriendlyValue());
            temp.addAllRewardIdList(userWineryDrinkerData.getRewardList());
            builder.addDrinkerArray(temp);
        }
        this.player.sendPacket(ClientProtocol.U_WINERY_DRINKER_DATA_SYNC, builder);
    }

    private void syncWineryArrayData(Collection<UserWineryData> list) {
        WineryProto.WineryDataArraySync.Builder builder = WineryProto.WineryDataArraySync.newBuilder();
        for (UserWineryData userWineryData : list) {
            WineryProto.WineryDataTemp.Builder temp = WineryProto.WineryDataTemp.newBuilder();
            temp.setWineryId(userWineryData.getWineryId());
            temp.setLevel(userWineryData.getLevel());

            WineryConfig wineryConfig = WineryConfigMgr.getWineryConfig(userWineryData.getWineryId());
            if (wineryConfig != null) {
                int wineryTypeTechnology = this.getWineryTypeTechnology(wineryConfig.getType(), userWineryData);
                double[] wineryMakeWeightArray = this.getWineryMakeWeightArray(wineryTypeTechnology);
                for (double v : wineryMakeWeightArray) {
                    temp.addNextWeightArray(v);
                }
            }
            builder.addWineryDataArray(temp);

        }
        this.player.sendPacket(ClientProtocol.U_WINERY_DATA_SYNC, builder);
    }

    private void syncWineryTypeArrayData() {
        WineryProto.WineryTypeDataArraySync.Builder builder = WineryProto.WineryTypeDataArraySync.newBuilder();
        Map<Integer, Integer> existMap = new HashMap<>();
        Map<Integer, WineryConfig> wineryConfigMap = WineryConfigMgr.getWineryConfigMap();
        for (WineryConfig wineryConfig : wineryConfigMap.values()) {
            int wineryConfigType = wineryConfig.getType();
            if (existMap.containsKey(wineryConfigType)) {
                continue;
            }
            WineryProto.WineryTypeTechnologyTemp.Builder typeTechnology = WineryProto.WineryTypeTechnologyTemp.newBuilder();
            int wineryTypeTechnology = this.getWineryTypeTechnology(wineryConfigType);
            typeTechnology.setWineryType(wineryConfigType);
            typeTechnology.setTechnologyValue(wineryTypeTechnology);
            double[] wineryMakeWeightArray = this.getWineryMakeWeightArray(wineryTypeTechnology);
            for (double v : wineryMakeWeightArray) {
                typeTechnology.addWeightArray(v);
            }
            builder.addList(typeTechnology);
            existMap.put(wineryConfigType, 1);
        }

        this.userWineryStaffMap.forEach((k, v) -> {
            WineryProto.WineryTypeStaffTemp.Builder staff = WineryProto.WineryTypeStaffTemp.newBuilder();
            staff.setStaffId(v.getStaffId());
            staff.setWineryType(v.getWineryType());
            staff.setPosition(v.getPosition());
            staff.setAbility(1);
            builder.addStaffList(staff);
        });

        this.userWineryStaffColdDownMap.forEach((k, v) -> {
            WineryProto.WineryStaffColdDownTemp.Builder staff = WineryProto.WineryStaffColdDownTemp.newBuilder();
            staff.setStaffId(v.getStaffId());
            staff.setFireTimeUnix(v.getFireTimeUnix());
            builder.addStaffColdDownList(staff);
        });

        this.getStaffSkill().forEach(builder::addSkillList);

        this.player.sendPacket(ClientProtocol.U_WINERY_TYPE_DATA_SYNC, builder);
    }

    public WineryProto.WineryStaffListRespMsg.Builder staffList() {
        WineryProto.WineryStaffListRespMsg.Builder builder = WineryProto.WineryStaffListRespMsg.newBuilder();
        builder.setRet(GameErrorCode.E_WINERY_STAFF_NOT_OPEN);
        return builder;
//        List<UserPatrons> userPatronsList = this.player.getModule(PatronsModule.class).getUserPatronsList();
//        for (UserPatrons userPatrons : userPatronsList) {
//            WineryProto.WineryStaffTemp.Builder staffInfo = this.getStaffInfo(userPatrons);
//            List<Integer> patronsSkinIdList = this.player.getModule(SkinModule.class).getPatronsSkinIdList(userPatrons.getPatronsId());
//            patronsSkinIdList.forEach(v -> {
//                WineryProto.WineryStaffSkinTemp.Builder skin = WineryProto.WineryStaffSkinTemp.newBuilder();
//                skin.setSkinId(v);
//                skin.setAddition(1);
//                staffInfo.addSkinAdditionList(skin);
//            });
//            builder.addList(staffInfo);
//        }
//        return builder;
    }

    private WineryProto.WineryStaffTemp.Builder getStaffInfo(UserPatrons userPatrons) {
        WineryProto.WineryStaffTemp.Builder builder = WineryProto.WineryStaffTemp.newBuilder();
        List<List<Integer>> wineryAbilityFormulaList = ConfigMgr.getWineryAbilityFormulaList();
        List<Integer> patronsSkinIdList = this.player.getModule(SkinModule.class).getPatronsSkinIdList(userPatrons.getPatronsId());
        Map<Integer, Integer> qualityMap = new HashMap<>();
        double userPatronsLevel = userPatrons.getLevel();
        Map<Integer, Integer> intensifyMap = new HashMap<>();
        for (Integer skinId : patronsSkinIdList) {
            SkinInfo skinInfo = SkinMgr.getSkinInfo(skinId);
            if (!qualityMap.containsKey(skinInfo.getQuality())) {
                qualityMap.put(skinInfo.getQuality(), 0);
            }
            qualityMap.put(skinInfo.getQuality(), qualityMap.get(skinInfo.getQuality() + 1));
            UserSkin userSkin = this.player.getModule(SkinModule.class).getUserSkin(skinId);
            if (!intensifyMap.containsKey(skinInfo.getQuality())) {
                intensifyMap.put(skinInfo.getQuality(), 0);
            }
            intensifyMap.put(skinInfo.getQuality(), intensifyMap.get(skinInfo.getQuality() + userSkin.getLevel()));
        }

        double totalAbility = 0;
        double a1;
        {
            List<Integer> integerList = wineryAbilityFormulaList.get(0);
            double p1 = integerList.get(0);
            double p2 = integerList.get(1);
            double p3 = integerList.get(2);
            double p4 = integerList.get(3);

            a1 = (p1 * Math.log(userPatronsLevel) + p2) * (p3 / 1000) + p4;
            a1 = Math.max(a1, 0);
            totalAbility = totalAbility + a1;
        }

        for (Map.Entry<Integer, Integer> entry : qualityMap.entrySet()) {
            List<Integer> integerList = wineryAbilityFormulaList.get(1 + (entry.getKey() - 1) * 2);
            double p1 = integerList.get(0);
            double p2 = integerList.get(1);
            double p3 = integerList.get(2);
            double p4 = integerList.get(3);
            double a = (p1 * Math.log(entry.getValue()) + p2) * (p3 / 1000) + p4;
            a = Math.max(a, 0);
            totalAbility = totalAbility + a;
        }

        for (Map.Entry<Integer, Integer> entry : intensifyMap.entrySet()) {
            List<Integer> integerList = wineryAbilityFormulaList.get(1 + (entry.getKey() - 1) * 2 + 1);
            double p1 = integerList.get(0);
            double p2 = integerList.get(1);
            double p3 = integerList.get(2);
            double p4 = integerList.get(3);
            double a = (p1 * Math.log(entry.getValue()) + p2) * (p3 / 1000) + p4;
            a = Math.max(a, 0);
            totalAbility = totalAbility + a;
        }
        int a = (int) totalAbility;
        builder.setAbility(a);
        builder.setStaffId(userPatrons.getPatronsId());
        builder.setStageAddition(99);
        return builder;
    }


    private void changeAromaRank(int value) {
        try {
            RankMgr.changeUserRank(eBigRankType.Normal.getValue(), player.getUserId(), BigInteger.valueOf(this.userWineryInfoData.getAromaValue()), eRankType.WineryAroma.getValue(), String.valueOf(this.userWineryInfoData.getBadgeLevel()));
            if (value > 0) {
                this.addActivityScoreRiseData(value);
                WineryAromaRankArgs wineryAromaRankArgs = new WineryAromaRankArgs(this.userWineryInfoData.getRankActivityDataMap());
                player.notifyListener(eGamePlayerEventType.WineryAromaRankActivityUserRank.getValue(), wineryAromaRankArgs);
                player.notifyListener(eGamePlayerEventType.WineryAromaRankActivityCrossUserRank.getValue(), wineryAromaRankArgs);
            }
        } catch (Exception ex) {
            log.error(ex);
        }
    }

    public int getTradeWarAdditionValue() {
        List<WineryProto.StaffSkillTemp.Builder> staffSkill = this.getStaffSkill();
        int total = 0;
        for (WineryProto.StaffSkillTemp.Builder v : staffSkill) {
            SkillInfo skillInfo = SkillMgr.getSkillInfo(v.getSkillId());
            if (skillInfo.getType() != eSkillType.WineryHomeAddition.getValue()) {
                continue;
            }
            int skillAddition = SkillMgr.getSkillAddition(skillInfo, v.getLevel());
            total = total + skillAddition;
        }
        return total;
    }

    public int getMonopolyMarketAdditionRatio() {
        List<WineryProto.StaffSkillTemp.Builder> staffSkill = this.getStaffSkill();
        int total = 0;
        for (WineryProto.StaffSkillTemp.Builder v : staffSkill) {
            SkillInfo skillInfo = SkillMgr.getSkillInfo(v.getSkillId());
            if (skillInfo.getType() != eSkillType.WineryHomeAddition.getValue()) {
                continue;
            }
            int skillAddition = SkillMgr.getSkillAddition(skillInfo, v.getLevel());
            total = total + skillAddition;
        }
        return total;
    }

    public int getChouSuanExpAdditionValue() {
        List<WineryProto.StaffSkillTemp.Builder> staffSkill = this.getStaffSkill();
        int total = 0;
        for (WineryProto.StaffSkillTemp.Builder v : staffSkill) {
            SkillInfo skillInfo = SkillMgr.getSkillInfo(v.getSkillId());
            if (skillInfo.getType() != eSkillType.WineryHomeAddition.getValue()) {
                continue;
            }
            int skillAddition = SkillMgr.getSkillAddition(skillInfo, v.getLevel());
            total = total + skillAddition;
        }
        return total;
    }

    public List<WineryProto.StaffSkillTemp.Builder> getStaffSkill() {
        List<WineryProto.StaffSkillTemp.Builder> list = new ArrayList<>();
        Map<Integer, Integer> wineryTypeAbility = this.getWineryTypeAbility();
        Map<Integer, List<Integer>> wineryDispatchStaffSkillListMap = ConfigMgr.getWineryDispatchStaffSkillListMap();
        wineryDispatchStaffSkillListMap.forEach((wineryType, SkillList) -> {

            int ability = 0;
            if (wineryTypeAbility.containsKey(wineryType)) {
                ability = wineryTypeAbility.get(wineryType);
            }

            int wineryDispatchSkillUpgrade = ConfigMgr.getWineryDispatchSkillUpgrade();
            List<SkillUpgradeInfo> skillUpgradeInfoList = SkillMgr.getSkillUpgradeInfoList(wineryDispatchSkillUpgrade);
            int level = 0;
            for (SkillUpgradeInfo skillUpgradeInfo : skillUpgradeInfoList) {
                if (ability < skillUpgradeInfo.getConsumeCount()) {
                    break;
                }
                level = skillUpgradeInfo.getLevel();
            }
            int levelCopy = level;
            SkillList.forEach(skillId -> {
                WineryProto.StaffSkillTemp.Builder builder = WineryProto.StaffSkillTemp.newBuilder();
                builder.setSkillId(skillId);
                builder.setLevel(levelCopy);
            });
        });
        return list;
    }

    public Map<Integer, Integer> getWineryTypeAbility() {
        Map<Integer, Integer> map = new ConcurrentHashMap<>();
        this.userWineryStaffMap.forEach((k, v) -> {
            if (!map.containsKey(v.getWineryType())) {
                map.put(v.getWineryType(), 0);
            }
            UserPatrons userPatrons = this.player.getModule(PatronsModule.class).getUserPatrons(v.getStaffId());
            WineryProto.WineryStaffTemp.Builder staffInfo = this.getStaffInfo(userPatrons);
            map.put(v.getWineryType(), map.get(v.getWineryType() + staffInfo.getAbility()));
        });

        return map;
    }


    public int getSkillMaxLevelAdd() {
        int addValue = 0;

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            return addValue;
        }

        BadgeConfig wineryBadgeConfig = BadgeConfigMgr.getWineryBadgeConfig(this.userWineryInfoData.getBadgeLevel());
        if (wineryBadgeConfig == null) {
            return addValue;
        }
        for (Integer skillId : wineryBadgeConfig.getSkillIdList()) {
            SkillInfo skillInfo = SkillMgr.getSkillInfo(skillId);
            if (skillInfo != null && skillInfo.getType() == eSkillType.SkillMaxLevelAdd.getValue()) {
                addValue += SkillMgr.getSkillAddition(skillInfo, this.userWineryInfoData.getBadgeLevel());
            }
        }
        return addValue;
    }

    private int getWineryTypeTechnology(int wineryType) {
        int addTechnologyValue = 0;
        for (WineryConfig wineryConfig : WineryConfigMgr.getWineryConfigMap().values()) {
            if (wineryConfig.getType() != wineryType) {
                continue;
            }
            UserWineryData userWineryData = this.getUserWineryData(wineryConfig.getId());
            if (userWineryData == null) {
                continue;
            }
            for (Integer skillId : wineryConfig.getSkillList()) {
                SkillInfo skillInfo = SkillMgr.getSkillInfo(skillId);
                if (skillInfo == null) {
                    continue;
                }
                if (wineryType != skillInfo.getParamList().get(2)) {
                    continue;
                }
                if (skillInfo.getType() == eSkillType.WineryTypeIncreaseTechnology.getValue()) { //124	提升酿酒工艺值	提升效果=a	初始固定值		1粮食酒、2花果酒、3高粱酒
                    addTechnologyValue += skillInfo.getParamList().get(0) + (userWineryData.getLevel() - 1) * skillInfo.getUpgradeParamList().get(0);
                }
            }
        }
        return addTechnologyValue;
    }

    private int getWineryTypeTechnology(int wineryType, UserWineryData preUpgradeUserWineryData) {
        int addTechnologyValue = 0;
        for (WineryConfig wineryConfig : WineryConfigMgr.getWineryConfigMap().values()) {
            if (wineryConfig.getType() != wineryType) {
                continue;
            }
            UserWineryData userWineryData = this.getUserWineryData(wineryConfig.getId());
            if (userWineryData == null) {
                continue;
            }
            for (Integer skillId : wineryConfig.getSkillList()) {
                SkillInfo skillInfo = SkillMgr.getSkillInfo(skillId);
                if (skillInfo == null) {
                    continue;
                }
                if (wineryType != skillInfo.getParamList().get(2)) {
                    continue;
                }
                int level = userWineryData.getLevel();
                if (userWineryData.getWineryId() == preUpgradeUserWineryData.getWineryId()) {
                    level++;
                }
                if (skillInfo.getType() == eSkillType.WineryTypeIncreaseTechnology.getValue()) { //124	提升酿酒工艺值	提升效果=a	初始固定值		1粮食酒、2花果酒、3高粱酒
                    addTechnologyValue += skillInfo.getParamList().get(0) + (level - 1) * skillInfo.getUpgradeParamList().get(0);
                }
            }
        }
        return addTechnologyValue;
    }


    private double[] getWineryMakeWeightArray(double wineryTypeTechnology) {
        List<List<Integer>> wineryProcessWeightFormula1List = ConfigMgr.getWineryProcessWeightFormula1List();
        double[] weightArray = {0, 0, 0, 0, 0};
        double totalWeight1_5 = 0;
        for (int i1 = 0; i1 < wineryProcessWeightFormula1List.size(); i1++) {
            List<Integer> integerList = wineryProcessWeightFormula1List.get(i1);
            double a = integerList.get(0);
            double b = integerList.get(1);
            double p = integerList.get(2);
            double d = integerList.get(3);
            double c = integerList.get(4);

            double step1 = wineryTypeTechnology - p;
            double step2 = (a * Math.pow(step1, 2));
            double step3 = (b * step1);
            double step4 = ((step2 + step3) / d);
            double step5 = step4 + c;
            double result = Math.max(step5, 0);
            weightArray[i1] = result;
            totalWeight1_5 = totalWeight1_5 + result;
        }
        double totalWeight = 0;
        for (double v : weightArray) {
            totalWeight = totalWeight + v;
        }
        for (int i1 = 0; i1 < weightArray.length; i1++) {
            weightArray[i1] = weightArray[i1] / totalWeight;
        }

        List<List<Integer>> wineryProcessProbabilityFormula = ConfigMgr.getWineryProcessProbabilityFormula();
        for (int i1 = 0; i1 < wineryProcessProbabilityFormula.size(); i1++) {
            List<Integer> integerList = wineryProcessProbabilityFormula.get(i1);
            Integer e = integerList.get(0);
            Integer f = integerList.get(1);
            if (wineryTypeTechnology > e) {
                weightArray[i1] = Math.max(weightArray[i1], f / 1000.0);
            }
        }
        totalWeight = 0;
        for (double v : weightArray) {
            totalWeight = totalWeight + v;
        }
        for (int i1 = 0; i1 < weightArray.length; i1++) {
            weightArray[i1] = weightArray[i1] / totalWeight;
        }
        return weightArray;
    }


    private int getDrinkerIncomeFinalValue(int friendlyValue, int baseIncome) {
        int incomeFinal = baseIncome;
        List<WineryDrunkFriendlyConfig> wineryDrunkFriendlyConfigs = ConfigMgr.getWineryDrunkFriendlyConfigs();
        int addition = 0;
        for (WineryDrunkFriendlyConfig wineryDrunkFriendlyConfig : wineryDrunkFriendlyConfigs) {
            if (friendlyValue >= wineryDrunkFriendlyConfig.getFriendly()) {
                if (addition < wineryDrunkFriendlyConfig.getAddition()) {
                    addition = wineryDrunkFriendlyConfig.getAddition();
                }
            }
        }
        if (addition > 0) {
            double multi = 1.0 + (double) addition / 1000.0;
            double result = (double) baseIncome * multi + 0.5;
            incomeFinal = (int) result;
        }
        return incomeFinal;
    }


    private void addActivityScoreRiseData(long aromaValue) {
        this.activityRankLock.lock();
        try {
            List<Integer> activityIdList = NormalActivityMgr.getOpenWineryAromaRankActivityIdList();
            Map<Integer, ActivityRank> rankActivityDataMap = this.userWineryInfoData.getRankActivityDataMap();
            if (activityIdList.isEmpty()) {
                return;
            }
            for (int activityId : activityIdList) {
                ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
                if (!ActivityMgr.activityInTime(activityInfo)) {
                    continue;
                }
                if (!rankActivityDataMap.containsKey(activityId)) {
                    ActivityRank data = new ActivityRank();
                    data.setActivityId(activityId);
                    rankActivityDataMap.put(activityId, data);
                }
                ActivityRank data = rankActivityDataMap.get(activityId);
                data.addScore(aromaValue);
            }
            this.userWineryInfoData.setUpdateOption();
        } finally {
            this.activityRankLock.unlock();
        }
    }


    /**
     * 清理过期的活动数据
     */
    private void clearActivityDataOutTime() {

        this.activityRankLock.lock();
        try {
            Map<Integer, ActivityRank> rankActivityDataMap = this.userWineryInfoData.getRankActivityDataMap();
            if (rankActivityDataMap == null || rankActivityDataMap.isEmpty()) {
                return;
            }

            List<Integer> needRemoveList = new ArrayList<>();
            for (ActivityRank activityData : rankActivityDataMap.values()) {
                List<Integer> activityIdList = NormalActivityMgr.getOpenWineryAromaRankActivityIdList();
                if (!activityIdList.contains(activityData.getActivityId())) {
                    needRemoveList.add(activityData.getActivityId());
                }
            }
            if (needRemoveList.size() > 0) {
                for (Integer activityId : needRemoveList) {
                    rankActivityDataMap.remove(activityId);
                }
                this.userWineryInfoData.setUpdateOption();
            }
        } finally {
            this.activityRankLock.unlock();
        }
    }

    private void addWineryItemCount(int itemId, int itemNum) {
        if (!this.userWineryItemInfoMap.containsKey(itemId)) {
            this.userWineryItemInfoMap.put(itemId, new ExtensionWineryItemInfo(itemId));
        }
        ExtensionWineryItemInfo extensionWineryItemInfo = this.userWineryItemInfoMap.get(itemId);
        extensionWineryItemInfo.addNum(itemNum);
    }

    public WineryProto.WineryItemSkillUpgradeResp.Builder wineryItemSkillUpgrade(int itemId) {
        WineryProto.WineryItemSkillUpgradeResp.Builder builder = WineryProto.WineryItemSkillUpgradeResp.newBuilder();

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            builder.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return builder;
        }

        if (!this.userWineryItemInfoMap.containsKey(itemId)) {
            this.userWineryItemInfoMap.put(itemId, new ExtensionWineryItemInfo(itemId));
        }
        ExtensionWineryItemInfo itemInfo = this.userWineryItemInfoMap.get(itemId);
        SkillInfo skillInfo = SkillMgr.getSkillWith(eSkillType.PatronsCookSkill.getValue(), itemId);
        if (skillInfo == null) {
            builder.setRet(GameErrorCode.E_WINERY_ITEM_SKILL_NOT_FOUND);
            return builder;
        }
        if(skillInfo.getMaxLevel() <= itemInfo.getLevel()){
            builder.setRet(GameErrorCode.E_ERROR_DATA);
            return builder;
        }
        int nextLevel = itemInfo.getLevel() + 1;
        SkillUpgradeInfo skillUpgradeInfo = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), itemInfo.getLevel());
        if (skillUpgradeInfo == null) {
            builder.setRet(GameErrorCode.E_WINERY_ITEM_SKILL_NOT_FOUND);
            return builder;
        }

        if (itemInfo.getNum() < skillUpgradeInfo.getConsumeCount()) {
            builder.setRet(GameErrorCode.E_WINERY_ITEM_NOT_ENOUGH);
            return builder;
        }
        itemInfo.setLevel(nextLevel);
        this.updateExtensionWineryItemInfoDB();
        builder.setItemId(itemId);
        builder.setLevel(nextLevel);
        //同步商铺赚速
        player.getModule(EarnSpeedModule.class).scheduleAddSilver();

        List<UserPatrons> userPatronsList = this.player.getModule(PatronsModule.class).getUserPatronsList();
        this.player.getModule(PatronsModule.class).onPatronsListChange(userPatronsList);

        return builder;
    }

    /**
     * 酒品一键升级所有到最高级
     */
    public WineryProto.WineryItemSkillUpgradeOneKeyResp.Builder wineryItemSkillUpgradeOneKey() {
        WineryProto.WineryItemSkillUpgradeOneKeyResp.Builder builder = WineryProto.WineryItemSkillUpgradeOneKeyResp.newBuilder();
        builder.setRet(0);
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Winery.getValue())) {
            builder.setRet(GameErrorCode.E_WINERY_NOT_OPEN);
            return builder;
        }

        for (Map.Entry<Integer, ExtensionWineryItemInfo> entry : userWineryItemInfoMap.entrySet()) {
            ExtensionWineryItemInfo itemInfo = entry.getValue();
            int itemId = itemInfo.getId();
            SkillInfo skillInfo = SkillMgr.getSkillWith(eSkillType.PatronsCookSkill.getValue(), itemId);
            if (skillInfo == null) {
                continue;
            }
            int oldLv = itemInfo.getLevel();
            if(oldLv == 0){
                continue;
            }
            int addLv = 0;
            for (int i = 0; i < 100; i++) {
                SkillUpgradeInfo skillUpgradeInfo = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), itemInfo.getLevel() + i);
                if(skillUpgradeInfo == null){
                    continue;
                }
                if(skillUpgradeInfo.getConsumeCount() <= 0){
                    break;
                }
                if (itemInfo.getNum() < skillUpgradeInfo.getConsumeCount()) {
                    break;
                }
                addLv++;
            }

            if(addLv > 0 ){
                itemInfo.setLevel(itemInfo.getLevel() + addLv);
                WineryProto.WineryItemSkillUpgradeResultTemp.Builder temp = WineryProto.WineryItemSkillUpgradeResultTemp.newBuilder();
                temp.setItemId(itemInfo.getId());
                temp.setNowLv(itemInfo.getLevel());
                temp.setOldLv(oldLv);
                builder.addResult(temp);
            }
        }

        if(builder.getResultCount() > 0) {
            this.updateExtensionWineryItemInfoDB();
            //同步商铺赚速
            player.getModule(EarnSpeedModule.class).scheduleAddSilver();

            List<UserPatrons> userPatronsList = this.player.getModule(PatronsModule.class).getUserPatronsList();
            this.player.getModule(PatronsModule.class).onPatronsListChange(userPatronsList);
        }
        return builder;
    }

    public Map<Integer, ExtensionWineryItemInfo> getUserWineryItemInfoMap() {
        return userWineryItemInfoMap;
    }


    /**
     * 更新勋章
     */
    public void updateBadge() {
        if (SystemOpenMgr.systemOpen(player, eSystemId.BadgeShow.getValue())) {
            if (userWineryInfoData == null) {
                return;
            }
            BadgeConfig wineryBadgeConfig = BadgeConfigMgr.getWineryBadgeConfig(userWineryInfoData.getBadgeLevel());
            if (wineryBadgeConfig == null) {
                return;
            }
            player.getModule(BadgeModule.class).addBadge(wineryBadgeConfig.getId(), eBadgeType.Winery.getValue());
        }
    }

    public Map<Integer, UserWineryDrinkerData> getUserWineryDrinkerDataMap() {
        return userWineryDrinkerDataMap;
    }

    public int setAutoDrinkPausePatron(List<Integer> pauseList){
        if (userWineryInfoData == null){
            return GameErrorCode.E_WINERY_NOT_OPEN;
        }
        if (pauseList == null) {
            return GameErrorCode.E_ERROR_DATA;
        }
        for (int patronId: pauseList){
            UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(patronId);
            if (userPatrons == null) {
                return GameErrorCode.E_PATRONS_NO_FOUND;
            }
        }
        userWineryInfoData.setPausePatron(pauseList);
        userWineryInfoData.setUpdateOption();

        WineryProto.WineryChooseOneKeyPausePatronResp.Builder builder = WineryProto.WineryChooseOneKeyPausePatronResp.newBuilder();
        builder.setRet(0);
        builder.addAllPatronId(pauseList);

        player.sendPacket(ClientProtocol.U_WINERY_CHOOSE_ONE_KEY_PAUSE_PATRON,builder);

        return 0;
    }
}
